home *** CD-ROM | disk | FTP | other *** search
- /*
- C* -- global variable definitions.
-
- Source: glb.c
- Started: April 2, 1986
- Version:
- December 18, 1986
- March 7, 1989
-
- PUBLIC DOMAIN SOFTWARE
-
- The CSTAR program was placed in the public domain on June 15, 1991,
- by its author and sole owner,
-
- Edward K. Ream
- 1617 Monroe Street
- Madison, WI 53711
- (608) 257-0802
-
- CSTAR may be used for any commercial or non-commercial purpose.
-
- See cstar.h or cstar.c for a DISCLAIMER OF WARRANTIES.
- */
- #define no_extern 1
- #include "cstar.h"
-
- /*
- ========= global tables =========
- */
- char * FAR xzp_tab [] = {
- "<NULL>",
- "abcd", "add", "adda", "addi", "addq",
- "addx", "and", "addi", "asl", "asr",
- "bchg", "bclr", "bra", "bset", "bsr",
- "btst", "bxx", "chk", "clr", "cmp",
- "cmpa", "cmpi", "cmpm", "dbxx", "divs",
- "divu", "eor", "eori", "exg", "ext",
- "jmp", "jsr", "lea", "link", "lsl",
- "lsr", "move", "movea", "movem", "movep",
- "moveq", "muls", "mulu", "nbcd", "neg",
- "negx", "nop", "not", "or", "ori",
- "pea", "reset", "rol", "ror", "roxl",
- "roxr", "rte", "rtr", "rts", "sbcd",
- "sxx", "stop", "sub", "suba", "subi",
- "subq", "subx", "swap", "tas", "trap",
- "trapv", "tst", "unlk",
-
- "mods", "modu",
-
- "bcc", "bcs", "beq", "bge", "bgt",
- "bhi", "ble", "bls", "blt", "bmi",
- "bne", "bpl", "bvc", "bvs",
-
- "dbcc", "dbcs", "dbeq", "dbf", "dbge",
- "dbgt", "dbhi", "dble", "dbls", "dblt",
- "dbmi", "dbne", "dbpl", "dbt", "dbvc",
- "dbvs",
-
- "scc", "scs", "seq", "sf", "sge",
- "sgt", "shi", "sle", "sls", "slt",
- "smi", "sne", "spl", "st", "svc",
- "svs",
-
- "addsp", "adjsp", "base", "bss", "data",
- "dc", "dcb", "dcl", "dcw", "ds",
- "dsb", "dsl", "dsw", "nobase", "org",
- "pop", "push", "subsp", "text",
-
- "<LABEL>", "<ULABEL>", "<LITERAL>", "<O_LOCATION>", "<LINE>",
- "<Q_BRN>"
- };
-
- char * FAR xlentab[] = {
- "", ".b", ".w", "<error>", ".l"
- };
-
- char * FAR arp_tab [] = {
- "<NULL>",
- "a0", "a1", "a2", "a3", "a4", "a5", "a6", "a7",
- "a0w", "a1w", "a2w", "a3w", "a4w", "a5w", "a6w", "a7w",
-
- "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d7",
- "d0w", "d1w", "d2w", "d3w", "d4w", "d5w", "d6w", "d7w",
- "d0b", "d1b", "d2b", "d3b", "d4b", "d5b", "d6b", "d7b",
-
- "ccr", "pc", "ssp", "sspw", "ssr",
-
- "cc", "cs", "eq", "f", "ge", "gt", "hi", "le",
- "ls", "lt", "mi", "ne", "pl", "t", "vc", "vs"
- };
-
- int FAR reg_size[] = {0,
- 4, 4, 4, 4, 4, 4, 4, 4,
- 2, 2, 2, 2, 2, 2, 2, 2,
- 4, 4, 4, 4, 4, 4, 4, 4,
- 2, 2, 2, 2, 2, 2, 2, 2,
- 1, 1, 1, 1, 1, 1, 1, 1,
- 1, 4, 4, 2, 2 };
-
-
- int FAR reg_itb[] = {
- 0,
-
- 0, 1, 2, 3, 4, 5, 6, 7,
- 0, 1, 2, 3, 4, 5, 6, 7,
-
- 0, 1, 2, 3, 4, 5, 6, 7,
- 0, 1, 2, 3, 4, 5, 6, 7,
- 0, 1, 2, 3, 4, 5, 6, 7
- };
-
- int FAR d_rtb[] = {
- R_D0, R_D1, R_D2, R_D3, R_D4, R_D5, R_D6, R_D7
- };
-
- int FAR a_rtb[] = {
- R_A0, R_A1, R_A2, R_A3, R_A4, R_A5, R_A6, R_A7
- };
-
- int FAR x_rtb[] = {
- 0,
- R_A0, R_A1, R_A2, R_A3, R_A4, R_A5, R_A6, R_A7,
- R_A0, R_A1, R_A2, R_A3, R_A4, R_A5, R_A6, R_A7,
- R_D0, R_D1, R_D2, R_D3, R_D4, R_D5, R_D6, R_D7,
- R_D0, R_D1, R_D2, R_D3, R_D4, R_D5, R_D6, R_D7,
- R_D0, R_D1, R_D2, R_D3, R_D4, R_D5, R_D6, R_D7,
- R_CCR, R_PC, R_SP, R_SPW, R_SR, R_USP,
- CC_CC, CC_CS, CC_EQ, CC_F, CC_GE, CC_GT, CC_HI, CC_LE,
- CC_LS, CC_LT, CC_MI, CC_NE, CC_PL, CC_T, CC_VC, CC_VS
- };
-
- char * FAR kp_tab [] = {
- "<NULL>",
-
- "auto", "char", "const", "double", "extern",
- "float", "int", "long", "register", "short",
- "static", "typedef", "signed", "struct", "union",
- "unsigned", "void", "volatile",
-
- "break", "case",
- "continue", "default", "do", "else", "for",
- "goto", "if", "return", "switch", "while",
-
- "entry", "enum", "sizeof",
-
- ",", "<newline>", ";", "[", "{", "(", "]", "}", ")",
-
- ":", "?",
-
- "ARRAY", "->", ".", "&&", "||", ",",
-
- "=",
- "&=", "/=", "<<=", "-=", "%=",
- "|=", "+=", ">>=", "*=", "^=",
-
- "&", "|", "+", "*", "^",
- "/", "<<", "-", "%", ">>",
-
- "==", ">=", ">", "<=", "<", "!=",
-
- "--", "++", "!", "~",
-
- "(cast)", "post--", "post++", "pre--", "pre++",
- "&", "-", "+", "*", "call",
-
- "A-reg", "CC-reg", "character", "D-reg", "EOF", "EOP",
- "X-reg", "id", "integer", "long integer", "pseudo-op",
- "string", "pseudo-function",
- "boolean", "label"
- };
-
- /*
- ========= global variables =========
- */
-
- /*
- The variable ch should be allocated a register if possible.
- */
- unsigned char ch; /* current character */
-
- int nest_flag = FALSE; /* TRUE if comments can nest. */
- int full_c = FALSE; /* TRUE if full C allowed. */
- int array_opt = FALSE; /* TRUE for normal subscript computation */
- int no_local = TRUE; /* TRUE for no local names in ass'y output */
-
- /*
- Internal flags: These allow accurate timing statistics to be gathered
- by suppressing various phases of the compiler. They also enable dumping of
- internal data structures and tokens to the output.
-
- These flags correspond to the following command line arguments.
-
- -noparse Suppress parsing.
- -nomacro Suppress macro expansion.
- -nogen Suppress code generation.
- -nopeep Suppress peephole optimizer.
-
- -tokens Output tokens.
- -tree Output parse tree.
- -code1 Output code list before peephole.
- -code2 Output code list after peephole.
- */
- bool nomacro_flag = FALSE;
- bool noparse_flag = FALSE;
- bool nogen_flag = FALSE;
- bool nopeep_flag = FALSE;
-
- bool token_flag = FALSE;
- bool tree_flag = FALSE;
- bool code1_flag = FALSE;
- bool code2_flag = FALSE;
-
-
- /*
- ----- PREPROCESSOR AND TOKENS -----
- */
-
- /*
- The code assumes that no token or string will ever be longer than
- MAX_SYMBOL. If that ever is not so the program may crash. Thus,
- MAX_SYMBOL should be very large -- say 1000 or more.
- */
- char t_symbol [MAX_SYMBOL]; /* The spelling of the token. */
- int t_length; /* The length of the token (in the text)*/
- long t_value; /* Value of integer constants. */
- int t_type; /* The token itself or it's class. */
- int t_subtype; /* The subtype of token class. */
-
- /*
- The following globals are set ONLY by the system module.
- They are picked up and used by the preprocessor and the
- parser.
- */
- char * t_file; /* Name of current input file. */
- int t_line; /* Line number within file. */
- int t_inlevel; /* Current input file level. */
-
- /*
- Globals for use internally to the token routines.
- */
- short t_ifstack [MAX_IF]; /* Stack for nexted #if's */
- int t_iflevel; /* Nexting depth of #if's */
- long t_errcount; /* Number of errors seen. */
-
- int t_evalstk [MAX_EVAL]; /* Operator/operand stack. */
- int t_opptr; /* Operator index to evalstk[]. */
- int t_valptr; /* Operand index to evalstk[]. */
-
- struct u_node undef_list; /* Initial undef list for PP. */
-
- /*
- Defines for the path table.
- This table is used to search for #include files.
- */
- char * paths [MAX_PATHS]; /* Pointers to path names. */
- int n_paths = 0; /* Number of paths defined. */
-
- /*
- ----- PARSING -----
- */
-
- /*
- this is just too inconvenient to return as a return-value
- it is needed for code generation
- */
- int call_1arg; /* Incremented by the parser when it sets up a
- call to a function having one argument */
-
- /*
- ----- CODE GENERATION -----
- */
- /* g1.c */
- int segment;
- struct type_node * intrn_decl; /* needed from exp.c to pick up block and
- implicit internal decls e.g. strings */
- struct type_node * intrn_ptr;
-
- /*
- reg.c:
- These do not appear in glb.h since they are used by so few routines.
- */
- int na_free; /* needed by g2.c to check for temps */
- int nd_free;
- int sa_used [8]; /* needed by g1.c for register push and pop */
- int sd_used [8];
- int sa_push [8];
- int sd_push [8];
- int sa_avail[8];
- int sd_avail[8];
- int ss_count, ss_forks, ss_bot; /* needed by g2.c for branch points */
-
- /* exp.c */
-
- struct node * code_head; /* Head of list of global code list. */
- struct node * code_tail; /* Pointer to last node in list. */
-
- int u_lab = 0; /* Number of the current user label. */
- int cur_lab = 0; /* Number of the current internal label. */
- struct scope_node scope; /* Current scope. */
-
- int f_base; /* See par.c; this has no conceivable use as
- an integer */
-
- struct type_node * byte_type; /* Fixed typenode */
- struct type_node * int_type; /* Fixed integer typenode */
- struct type_node * long_type; /* Fixed long typenode */
-
- struct node * a0_loc;
- struct node * d0_loc;
- struct node * a6_loc; /* frame reg */
- struct node * a7_loc; /* stack itself */
- struct node * sr_loc; /* sr */
- struct node * ccr_loc; /* ccr */
- struct node * push_loc; /* *--sp */
- struct node * nopush_loc; /* *--sp */
- struct node * pop_loc; /* *sp++ */
- struct node * one_loc; /* constant 1 */
- struct node * zero_loc;
-
- /* g2.c */
- struct diop ops_true = {X_BRA, Q_BRN};
- struct diop ops_false = {Q_BRN, X_BRA};
- struct diop ops_cond = {X_BNE, X_BEQ};
-
- /*
- ----- C* REGISTERS -----
- */
-
- /* -----
- long d0, d1, d2, d3, d4, d5, d6, d7;
- char *a0, *a1, *a2, *a3, *a4, *a5, *a6, *a7, *sp;
- int a0w, a1w, a2w, a3w, a4w, a5w, a6w;
- char ccr;
- int ssr, spw;
- ----- */
-
- /* remove these after the next comp */
- char * f_name;
- char * f_locals;
- char * f_formals;
-